<template>
    <div class="swiper">
        <div class="title">
            <span class="title-left">{{name}}</span>
           <a href="#/kandeng" class="title-right">刊登</a>
        </div>
        <div class="swiper-father swiper-other">
            <swiper :options="swiperOption" class="swiper-wrap"  ref="mySwiper" v-if="list.length!=0">
                <swiper-slide v-for="(item,index) in list" :key="index" >
                    <div class="swiper-box">
                        <a :href="'#/detail/' + img.brand_id" v-for="img in item" class="swiper-box-inner">
                            <!--<a :href="'#/detail/' + img.brand_id">-->
                                <div class="swiper-box-inner-img">
                                    <img  :src="brandImg+img.brand_logo" alt="" />
                                </div>
                                <div class="swiper-box-text">{{img.brand_name}}</div>
                            <!--</a>-->
                        </a>
                    </div>
                </swiper-slide>
            </swiper>
            <!-- 常见的小圆点 -->
            <div :class="'swiper-button-next-'+name" class="swiper-button-next" slot="button-next"></div>
            <div :class="'swiper-button-prev-'+name" class="swiper-button-prev"  slot="button-prev"></div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "swiper-ad",
        props:{
            name:{
                type:String
            },
            list:{
                type:Array,
                default:() => {
                    return []
            }
            }
        },
        data() {
            const that = this;
            return {
                imgIndex: 1,
                swiperOption: {
                    //是一个组件自有属性，如果notNextTick设置为true，组件则不会通过NextTick来实例化swiper，也就意味着你可以在第一时间获取到swiper对象，假如你需要刚加载遍使用获取swiper对象来做什么事，那么这个属性一定要是true
                    notNextTick: true,
                    //循环
                    loop: true,
                    //设定初始化时slide的索引
                    initialSlide: 0,
                    //自动播放
                    autoplay: {
                        delay: 150000,
                        stopOnLastSlide: false,
                        /* 触摸滑动后是否继续轮播 */
                        disableOnInteraction: false
                    },
                    //滑动速度
                    speed: 800,
                    //滑动方向
                    direction: "horizontal",
                    //小手掌抓取滑动
                    grabCursor: true,
                    on: {
                        //滑动之后回调函数
                        slideChangeTransitionStart: function() {
                            /* realIndex为滚动到当前的slide索引值 */
                            that.imgIndex= this.realIndex - 1;
                        },
                    },
                    //分页器设置
                    navigation: {
                        nextEl: '.swiper-button-next-'+this.name, //前进按钮的css选择器或HTML元素。
                        prevEl: '.swiper-button-prev-'+this.name, //后退按钮的css选择器或HTML元素。
                        hideOnClick: true, //点击slide时显示/隐藏按钮
                        disabledClass: 'my-button-disabled', //前进后退按钮不可用时的类名。
                        hiddenClass: 'my-button-hidden', //按钮隐藏时的Class
                    },
                },
                // banner:[
                //     [
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"1231321231231312312313212312313123123132123123131231231321231231312312313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //     ],
                //     [
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //     ],
                //     [
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //         {
                //             image:"https://sponsor-static.segmentfault.com/8552c525b1f77f394dc07b64cd71cf11.png",
                //             text:"12313212312313123"
                //         },
                //     ],
                // ]
            }
        },
    }
</script>

<style scoped lang="less">
    a{
        color: #000000;
    }
    .swiper{
        width: 100%;
        height: 100%;
    }
    .title{
        height: 48px;
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border-bottom: 4px solid #2e436d;
        margin-bottom: 15px;
        .title-left{
            padding:  0 18px;
            height: 48px;
            line-height: 48px;
            font-size: 24px;
            background-color:#2e436d;
            color: #ffffff;
        }
        .title-right{
            cursor: pointer;
            font-size: 16px;
            line-height: 16px;
            padding: 5px;
            color: gray;
            border: 1px solid gray;
        }
    }
    .swiper-father{
        width: 100%;
        /*height: 180px;*/
        position: relative;
        margin: 0 auto;
    }
    .swiper-button-next{
        right: -30px;
    }
    .swiper-button-prev{
        left: -30px;
    }
    .swiper-wrap{
        width: 100%;
        height: 100%;
        .swiper-box{
            width: 100%;
            height: 100%;
            /*display: flex;*/
            /*flex-direction: row;*/
            /*justify-content: space-around;*/
            .swiper-box-inner{
                width: 24%;
                display: inline-block;
                margin: 0 0.5%;
                color: #000000;
                font-size: 16px;
                box-sizing: border-box;
                border: 1px solid #e6e6e6;
                .swiper-box-inner-img{
                    width: 100%;
                    height: 112px;
                    overflow: hidden;

                }
                img{
                    width: 100%;
                    height: auto;
                }
                .swiper-box-text{
                    text-align: center;
                    width: 100%;
                    height: 30px;
                    line-height: 30px;
                    box-sizing: border-box;
                    padding:  0 5px;
                    overflow: hidden;/*超出部分隐藏*/
                    text-overflow:ellipsis;/* 超出部分显示省略号 */
                    white-space: nowrap;/*规定段落中的文本不进行换行 */
                }
            }
        }
    }

</style>
<style lang="less">
    .swiper-other{
        .swiper-box{
            justify-content: flex-start !important;
        }
    }
</style>